<?php

namespace App\Admin\Selectable;

use Encore\Admin\Grid\Filter;
use Encore\Admin\Grid\Selectable;
use App\Models\yth\GoodsModel;
use App\Models\yth\GoodsTypeModel;
use App\Models\yth\WarehouseModel;
use App\Models\DataDictionaryModel;

class GoodsSelect extends Selectable
{
    public $model = GoodsModel::class;

    public function make()
    {
        $this->model()->where(['status'=>1])->orderBy('created_at','desc');

        $this->column('goods_code','产品编码')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('type_id','产品分类')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : GoodsTypeModel::selectValue('id',$filed);
        });

        $this->column('goods_name','产品名称')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });
        $this->column('goods_size','尺寸')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('goods_unit','单位')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('goods_placement_position','货物摆放位置')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('goods_stock','库存')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('goods_safety_stock','安全库存')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $this->column('warehouse_id','所属仓库')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : WarehouseModel::selectValue('id',$filed);
        });

        $this->column('shipment_type','发货类型')->using(DataDictionaryModel::ShipmentType, '未知')->label([
            1 => 'success',
            2 => 'info',
        ], 'success');


        $this->filter(function($filter){
            $filter->column(1/2, function ($filter) {
                $filter->like('goods_code','产品编码');
            });
            $filter->column(1/2, function ($filter) {
                $filter->like('goods_name','产品名称');
            });

            $filter->disableIdFilter();
        });
    }
}